<template>
  <div>
    <FormPanel
      ref="formPanel"
      :list="initForm"
      :cols="3"
      :formType="value.type"
      :labelWidth="100"
      :isSubmitBtn="false"
      @formChange="changeHandle"/>
    <div class="dialogBottmView">
      <el-button @click="closeDialog">取 消</el-button>
      <el-button @click="saveDialog" v-if="value.type!=='show'" type="primary">保 存</el-button>
    </div>
  </div>
</template>

<script>
import { dictionary } from '@/utils/dictMixin';
import { PHONE_PATTERN } from '@/utils/validate'; // 验证
export default {
  mixins: [dictionary],
  props:{
    value:{
      type:Object,
      default:{}
    }
  },
  data() {
    return {
      initForm: this.initFormFun(),
      formValue: {},
      formType:'add',
      initData:{}
    };
  },
  mounted() {
    this.init()
  },
  methods: {
    //初始化数据
    init() {
      // if (data.type === 'edit') {
      //   this.initForm.forEach(x => {
      //     x.initialValue = data.row[x.fieldName];
      //   });
      // }
    },
    //搜索数据
    initFormFun() {
      return [
       {
          type: 'UPLOAD_IMG',
          label: '上传图片',
          fieldName: 'UPLOAD_IMG',
          upload: {
            actionUrl: '', //上传的地址
            fixedSize: [300, 500], //剪裁尺寸
            isCalcHeight: false,
            limit: 1 //上传数量
          },
          initialValue: ''
        },
        {
          type: 'INPUT',
          label: '员工编号',
          fieldName: 'field1',
          placeholder: '请输入',
          initialValue: '',
          rules: [
            {
              required: true,
              message: '必填',
              trigger: 'blur'
            }
          ]
        },
        {
          type: 'INPUT',
          label: '员工姓名',
          fieldName: 'field01',
          placeholder: '请输入',
          initialValue: '',
          rules: [
            {
              required: true,
              message: '必填',
              trigger: 'blur'
            }
          ]
        },
        {
          type: 'SELECT',
          label: '性别',
          fieldName: 'field2',
          placeholder: '请选择',
          initialValue: '',
          itemList: this.createDictList('1008'),
          rules: [
            {
              required: true,
              message: '必填',
              trigger: 'change'
            }
          ]
        },
        {
          type: 'DATE',
          label: '出生日期',
          fieldName: 'DATE',
          valueFormat: 'yyyy-MM-dd', //返回数据格式
          initialValue: '2019-08-19',
          placeholder: '请选择',
          style: { width: '100%' },
          rules: [
            {
              required: true,
              message: '必填',
              trigger: 'change'
            }
          ]
        },
        {
          type: 'INPUT_TREE',
          label: '部门名称',
          fieldName: 'tid',
          placeholder: '请选择',
          itemList: [
            {
              //tree 数据源
              value: 1,
              text: '一级 1',
              children: [{ value: 4, text: '二级 1-1', children: [{ value: 9, text: '三级 1-1-1' }, { value: 10, text: '三级 1-1-2' }] }]
            }
          ],
          rules: [{ required: true, message: '错误提示信息', trigger: 'change' }]
        },
        {
          type: 'SELECT',
          label: '岗位名称',
          fieldName: 'field3',
          placeholder: '请选择',
          initialValue: '',
          itemList: this.createDictList('1008'),
          rules: [
            {
              required: true,
              message: '必填',
              trigger: 'change'
            }
          ]
        },
        {
          type: 'INPUT',
          label: '手机',
          fieldName: 'field03',
          placeholder: '请输入',
          initialValue: '',
          rules: [
            {
              required: true,
              message: '必填',
              trigger: 'blur'
            }
          ]
        },
        {
          type: 'INPUT',
          label: '电话',
          fieldName: 'field03',
          placeholder: '请输入',
          initialValue: ''
        },
        {
          type: 'INPUT',
          label: '身份证号',
          fieldName: 'field04',
          placeholder: '请输入',
          initialValue: '',
          rules: [
            {
              required: true,
              message: '必填',
              trigger: 'blur'
            }
          ]
        },{
          type: 'INPUT',
          label: '邮编',
          fieldName: 'field05',
          placeholder: '请输入',
          initialValue: ''
        },{
          type: 'INPUT',
          label: 'E-mail',
          fieldName: 'field05',
          placeholder: '请输入',
          initialValue: ''
        },
        {
          type: 'SELECT',
          label: '在职状态',
          fieldName: 'field4',
          placeholder: '请选择',
          initialValue: '',
          itemList: this.createDictList('1008'),
          rules: [
            {
              required: true,
              message: '必填',
              trigger: 'change'
            }
          ]
        },
        {
          type: 'DATE',
          label: '建档日期',
          fieldName: 'DATE1',
          valueFormat: 'yyyy-MM-dd', //返回数据格式
          initialValue: '',
          placeholder: '请选择',
          style: { width: '100%' }
        },{
          type: 'DATE',
          label: '入职日期',
          fieldName: 'DATE2',
          valueFormat: 'yyyy-MM-dd', //返回数据格式
          initialValue: '',
          placeholder: '请选择',
          style: { width: '100%' }
        },{
          type: 'DATE',
          label: '离职日期',
          fieldName: 'DATE3',
          valueFormat: 'yyyy-MM-dd', //返回数据格式
          initialValue: '',
          placeholder: '请选择',
          style: { width: '100%' }
        },
        {
          type: 'TEXT_AREA',
          label: '地址',
          fieldName: 'field10',
          rows: 3,
          initialValue: '',
          placeholder: '请输入'
        }
      ];
    },
    changeHandle(data){
      console.log(data)
      this.$emit('close', {type:'refresh',});
    },
    //保存
    saveDialog(){
      this.$refs.formPanel.SUBMIT_FORM()
    },
    //取消操作
    closeDialog() {
      this.$emit('close', { visible: false });
    }
  }
};
</script>